/**
 *  @邢玮 UI层提供系统对话
 * 基于antv提供多种形式提示机制，如，Drawer，Message,Modal,Notification ..
 * 如：app.message('浏览器版本不匹配,...')
 * */
import { message, notification, Drawer, Modal, Icon } from 'ant-design-vue'
import { partServer, soundServer } from 'anov-core'


class PopBox {
  constructor(opt){
    notification.config({
      getContainer: () => document.querySelector('#app')
    })
    this.config = {
      type: 'success',          //类型：success/error/info/warn
      title: '',                //标题
      content: '',              //内容
      duration: 3,              //duration后弹出框关闭
      top: '24px',              //距顶部距离
      onClose: function(){},    //关闭时的回调
      open:true
    }
    this.option = Object.assign(this.config, opt)
    this.config.open && this.open()
  }
  open(){}
  destroy(){}
}

class Msg extends PopBox  {
  constructor(opt) { 
    let option = {}
    option=Object.assign(option,opt)
    super(option);
    message.config({
      getContainer: () => document.querySelector('#app')
    })
  }
  open(params){
    this.option = Object.assign(this.option, params)
    message[this.option.type](this.option.content, this.option.duration, this.option.top, this.option.onClose)
  }
  destroy(){
    message.destroy()
  }
}


class Notice extends PopBox {
    constructor(opt) {
      var option = {
        key: '',    
        message: '',
        description: '',
        placement: 'topRight',
        onClick: function(){}
      }
      option=Object.assign(option,opt)
      super(option);
    }
    open(params) {
        this.option = Object.assign(this.option, params)
        this.option.message = this.option.title
        this.option.description = this.option.content
        notification.open(this.option)
    }
    close(key){
        notification.close(key)
    }
    destroy(){
        notification.destroy()
    }
    
}

class Amodal {
    constructor(opt) {
      this.option = {
        type: 'success',
        componentsName: 'modalSimple',
        onClose: function(){}
      }
    }
    open(params){
        this.option = Object.assign(this.option, params)
        if(partServer.getCompByTagName('modal')){
          let modal = partServer.getCompByTagName('modal')[0]
          modal.open(this.option)
        }
    }
    destroy(params){
        let modal = partServer.getCompByTagName('modal')[0]
        modal.destroy(this.option)
    }
}
function msg(opt){
  return new Msg(opt)
}

function notice(opt){
  return new Notice(opt)
}

let modal = new Amodal()
export { msg, notice, modal }

